package day04;

import java.util.Scanner;

/** 猜数字小游戏*/
public class Guessing {
    public static void main(String[] args) {
        /*Scanner sc = new Scanner(System.in);
        System.out.println("猜吧");
        int guess = sc.nextInt();
        int num =(int)(Math.random()*1000+1);
        while (guess != num){
            if(guess > num){
                System.out.println("猜大了");
            }else {
                System.out.println("猜小了");
            }
            System.out.println("猜把");
            guess = sc.nextInt();
        }
        System.out.println("恭喜您，猜对了");*/




        //while(true)  自造死循环 必须加break
        Scanner sc = new Scanner(System.in);
        int num = (int)(Math.random()*1000+1);
        while (true){         //--------------------------自造死循环
            System.out.println("猜吧");
            int guess = sc.nextInt();
            if(guess > num){
                System.out.println("猜大了");
            }else if(guess < num){
                System.out.println("猜小了");
            }else{
                System.out.println("恭喜您，猜对了");
                break;      //--------------------------跳出循环
            }
        }




    }
}
